package com.nearby.demand.adapter;

import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.OrientationHelper;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;

import com.nearby.demand.R;
import com.nearby.demand.model.News;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by lizhangqu on 2015/6/home_3.
 */
public class WorldDetailAdapter extends BaseRecyclerViewAdapter<News, WorldDetailAdapter.MyViewHolder> {

    public WorldDetailAdapter(List<News> list) {
        super(list);
    }


    @Override
    protected void bindDataToItemView(MyViewHolder myViewHolder, News item) {
        if(item.getType()==1){
            myViewHolder.setText(R.id.leave_message_name,item.getTitle());

        }else{
            RecyclerView recyclerView =  myViewHolder.getView(R.id.recycler_view_collect);
            List<News> list = new ArrayList<>();
            for (int i = 0 ; i <6;i++){
                News news = new News();
                news.setTitle("哈哈"+i);
                list.add(news);
            }
            recyclerView.setHasFixedSize(true);//固定尺寸
            LinearLayoutManager linearLayoutManager = new LinearLayoutManager(super.activity);
            linearLayoutManager.setOrientation(OrientationHelper.HORIZONTAL);
            recyclerView.setLayoutManager(linearLayoutManager);


            recyclerView.setAdapter(new CollectAdapter(list));
        }

    }
    @Override //获取item类型
    public int getItemViewType(int position) {
       return getItem(position).getType();
    }


    @Override
    public MyViewHolder onCreateViewHolder(ViewGroup viewGroup, int type) {
        if(type==0){
            return new MyViewHolder(inflateItemView(viewGroup, R.layout.ui_world_detail_top));
        }
        return new MyViewHolder(inflateItemView(viewGroup, R.layout.ui_world_detail_leave_message));
    }


    public class MyViewHolder extends BaseRecyclerViewAdapter.SparseArrayViewHolder {

        public MyViewHolder(View itemView) {
            super(itemView);

        }


    }

}
